const basePath = '/student'
import { get, post } from '@/axios'
import { h } from 'vue'
import { NDescriptions, NDescriptionsItem, NButton, NSpace } from 'naive-ui'
// 获取学生列表
export function list(params, callback) {
	get(basePath + '/list', params, callback)
}
export function saveAndUpdate(params, callback, formRef) {
	const url = params.id ? '/update' : '/add'
	post(`${basePath}${url}`, params, callback, formRef)
}
export function getInfo (id, callback) {
	get(`${basePath}/getInfo`, { id }, callback)
}
export function check (params, callback) {
	get(`${basePath}/check`, params, callback)
}
export function createColumns({ update, del }) {
	return [
		{
			title: '学号',
			key: 'no',
			width: 100
		},
		{
			title: '姓名',
			key: 'name',
			width: 100
		},
		{
			title: '手机号',
			key: 'phone',
			width: 150
		},
		{
			title: '邮箱',
			key: 'email',
			width: 180
		},
		{
			title: '状态',
			key: 'active',
			width: 100,
			render(row) {
				return h('span', { style: { color: row.active ? 'green' : 'red' } }, row.active ? '正常' : '退学')
			}
		},
		{
			title: '操作',
			key: 'active',
			width: 200,
			render(row) {
				return row.active ? <NSpace>
						<NButton type="info" size="small" onClick={() => update(row.id)}>修改</NButton>
						<NButton type="error" size="small" onClick={() => del(row.id, 0)}>删除</NButton>
					</NSpace> : <NButton type="warning" size="small" onClick={() => del(row.id, 1)}>恢复</NButton>
			}
		}
	]
}